<template>
	<el-button ref="elButton" icon="Download" v-bind="$attrs" @click.prevent="exportFn">
		导出
		<template v-for="(slotKey, i) in Object.keys($slots)" :key="i" #[slotKey]>
			<slot :name="slotKey"></slot>
		</template>
	</el-button>
</template>

<script setup name="MyButtonExport" lang="ts">
import { type ElMessageBoxOptions } from 'element-plus';

/**
 * props
 * @property {Function} load // 下载请求
 * @property {Object,String} confirmMsg // 确认弹窗参数
 */
const props = defineProps({
	load: {
		type: Function,
		required: true
	},
	confirmMsg: {
		type: [String, Object] as PropType<string | ElMessageBoxOptions>,
		default: () => ({})
	}
});
/**
 * 下载请求，内部调用从组件props传入‘load’函数
 * @Function exportFn
 */
function exportFn() {
	if (!props.load) {
		new Error('load 下载方法必须传');
		return;
	}
	confirmFn(props.confirmMsg)
		.then(() => {
			props.load();
		})
		.catch(() => {
			msgInfo('操作已取消！');
		});
}
</script>
